package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.consts.ErmsCodePrefix;
import com.sugon.dao.SpecialDevSafetyValveDao;
import com.sugon.entity.SpecialDevSafetyValveEntity;
import com.sugon.service.SpecialDevSafetyValveService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 特种设备-安全阀台账Service实现类
 *
 * @author sugon
 * @date 2021-09-08 16:30:40
 */
@Service("specialDevSafetyValveService")
public class SpecialDevSafetyValveServiceImpl implements SpecialDevSafetyValveService {
    @Autowired
    private SpecialDevSafetyValveDao specialDevSafetyValveDao;

    @Override
    public SpecialDevSafetyValveEntity queryObject(String id) {
        return specialDevSafetyValveDao.queryObject(id);
    }

    @Override
    public List<SpecialDevSafetyValveEntity> queryList(Map<String, Object> map) {
        return specialDevSafetyValveDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return specialDevSafetyValveDao.queryTotal(map);
    }

    @Override
    public String generateUniqueCode() {
        String lastestEquipmentCode = specialDevSafetyValveDao.getLastestEquipmentCode(ErmsCodePrefix.SAFETY_VALVE_CODE_PREFIX);
        return com.sugon.modules.utils.StrUtil.increase(lastestEquipmentCode, ErmsCodePrefix.SAFETY_VALVE_CODE_PREFIX, 5, 1);
    }

    @Override
    public int save(SpecialDevSafetyValveEntity specialDevSafetyValve) {
        specialDevSafetyValve.setId(RandomUtil.randomString(32));
        specialDevSafetyValve.setGmtCreate(DateUtil.date());
        specialDevSafetyValve.setCreateUser(ShiroUtils.getUserId());
        specialDevSafetyValve.setEquipmentCode(generateUniqueCode());
        return specialDevSafetyValveDao.save(specialDevSafetyValve);
    }

    @Override
    public int update(SpecialDevSafetyValveEntity specialDevSafetyValve) {
        specialDevSafetyValve.setGmtModified(DateUtil.date());
        specialDevSafetyValve.setUpdateUser(ShiroUtils.getUserId());
        return specialDevSafetyValveDao.update(specialDevSafetyValve);
    }

    @Override
    public int delete(String id) {
        return specialDevSafetyValveDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return specialDevSafetyValveDao.deleteBatch(ids);
    }
}
